package com.sunnada.demo.log;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: mybatisproject2
 * @description: 日志常用类
 * @author: 李瑞益
 * @create: 2018-11-07 14:24
 **/
public class LogCommon {
    public static Date toDate(String time, String format){
        DateFormat temp = new SimpleDateFormat(format);
        Date parse = null;
        try {
            parse = temp.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return parse;
    }

    public static Date formatDate(Date date, String format) {
        DateFormat temp = new SimpleDateFormat(format);
        String time = temp.format(date);
        return toDate(time,format);
    }

    public static String toString(Date time,String format){
        DateFormat temp = new SimpleDateFormat(format);
        String parse = null;
        parse = temp.format(time);
        return parse;
    }

    public static Date getBjTime(Date time){
        return new Date(time.getTime()-8*3600*1000);
    }
}
